import Vue from 'vue'
import Router from 'vue-router'
import User from '@/components/User'
import Book from "../components/Book";
import Layout from "../layout/Layout";
import Login from "../components/Login";
import Register from "../components/Register";
import Person from "../components/Person";
import News from "../components/News";

Vue.use(Router)

//解决 `NavigationDuplicated`报错问题
const originalPush = Router.prototype.push;
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err);
}

export default new Router({
  mode: "history",
  routes: [
    {
      path: '/',
      name: 'Layout',
      component: Layout,
      children: [
        {
          path: '',
          redirect: 'user'
        },
        {
          path: 'book',
          name: 'Book',
          component: Book
        },
        {

          path: 'user',
          name: 'User',
          component: User
        },
        {
          path: 'person',
          name: 'Person',
          component: Person
        },
        {
          path: 'news',
          name: 'News',
          component: News
        }
      ]
    },

    {
      path: '/login',
      name: 'Login',
      component: Login
    },
    {
      path: '/register',
      name: 'Register',
      component: Register
    }
  ]
})
